<?php

namespace app\api\validate;

use think\Validate;

class User extends Validate
{
    protected $rule = [
        "username" => "require",
        "phone_number" => "require|check_Phone",
        "code"=>"require|number|min:4",
        "type"=>["require","in"=>"1,2"],
        "sex"=>["require","in"=>"0,1,2"],
    ];
    protected $message = [
        "username" => "用户名不能为null",
        "phone_number" => "手机号不能为null！",
        "code.require"=>"验证码不能为null",
        "code.min"=>"验证码长度不低于4位",
        "code.number"=>"验证码必须为数字",
        "type.require"=>"登录类型不存在！",
        "type.in"=>"类型数值错误",
        "sex.require"=>"性别数值不存在",
        "sex.in"=>"性别类型数值错误",
    ];
    protected $scene=[
        "send_code"=>["phone_number"],
        "login"=>["phone_number","code","type"],
        "update_user"=>["username","sex"]
    ];
    protected function check_Phone($phone_number){
        if (empty($phone_number)){
            return "手机号不能为null";
        }elseif(!is_numeric($phone_number)){
            return "值必须为数字";
        }
        return preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#', $phone_number) ? true : "不为运营商手机号！！";

    }

}